package qdu.java.recruit.service.impl;

import org.springframework.stereotype.Service;
import qdu.java.recruit.entity.HREntity;
import qdu.java.recruit.mapper.HRMapper;
import qdu.java.recruit.service.HRService;

import javax.annotation.Resource;

@Service
public class HRServiceImpl implements HRService {

    @Resource
    private HRMapper HRMapper;

    @Override
    public HREntity getHR(int HRId) {
        return HRMapper.getHR(HRId);
    }

    @Override
    public boolean updateHR(HREntity HREntity) {

        int result = HRMapper.updateHR(HREntity);
        return result > 0;
    }

    @Override
    public boolean registerHR(HREntity HREntity) {

        String password = HREntity.getHrPassword();
        String mobile  = HREntity.getHrMobile();


        if(HRMapper.getHRByMobile(mobile) != null) {
            return false;
        }

        int result ;
            HREntity.setHrPassword(password);
            result = HRMapper.saveHR(HREntity);


        return result > 0;

    }

    @Override
    public boolean loginHR(String mobile, String password) {
        String passwordDB = HRMapper.getHRByMobile(mobile).getHrPassword();
        return password.equals(passwordDB);
    }

    @Override
    public HREntity getHRByMobile(String mobile){
        return HRMapper.getHRByMobile(mobile);
    }


    @Override
    public HREntity getHRByDepartmentId(int departmentId) {
        return HRMapper.getHRByDepartmentId(departmentId);
    }




}
